var e = require("../../@babel/runtime/helpers/objectSpread2"),
  t = require("../../@babel/runtime/helpers/regeneratorRuntime"),
  n = require("../../@babel/runtime/helpers/asyncToGenerator"),
  r = require("../../store/index"),
  a = require("../../utils/index"),
  o = require("./utils/index"),
  i = require("../../config/index"),
  s = require("../../utils/helper/map/index"),
  u = $.getMenuButtonBoundingClientRect().top,
  c = a.helper.tabCommon,
  l = a.helper.classifyCity,
  p = a.helper.location;
Page({
  componentPage: ["onReachBottom", "onPullDownRefresh", "onPageScroll"],
  useStore: function (e) {
    return {
      banner: e.global.bannerList,
      bannerList: [{
        badge: "热门",
        icon: "https://excavator-container.oss-cn-hangzhou.aliyuncs.com/file/icon-rent.png",
        id: "1",
        mode: 1,
        page_type: "fixed",
        page_value: "1",
        title: "求租机械",
        unique_id: "63f3316444d42",
        updated_at: "2023-02-21 10:18:44",
      }, {
        badge: "热门",
        icon: "https://excavator-container.oss-cn-hangzhou.aliyuncs.com/file/icon-machine.png",
        id: "2",
        mode: 2,
        page_type: "fixed",
        page_value: "2",
        title: "机械出租",
        unique_id: "63f3316444d43",
        updated_at: "2023-02-21 10:19:15",
      }, {
        badge: "",
        icon: "https://excavator-container.oss-cn-hangzhou.aliyuncs.com/file/icon-driver.png",
        id: "7",
        mode: 5,
        page_type: "fixed",
        page_value: "7",
        title: "驾驶员招聘",
        unique_id: "63f33939abcc1",
        updated_at: "2023-02-21 10:20:42",
      }, {
        badge: "",
        icon: "https://excavator-container.oss-cn-hangzhou.aliyuncs.com/file/%E5%AE%A2%E6%9C%8D%20%281%29.png",
        id: "7",
        page_type: "fixed",
        mode: 99,
        page_value: "7",
        title: "客服",
        unique_id: "63f33939abcc1",
        updated_at: "2023-02-21 10:20:42",
      }],
      areaTree: e.storage.areaTree,
      userInfo: e.storage.userInfo,
      memberInfo: e.user.userInfo,
      isShowFreeInviteDialog: e.global.isShowFreeInviteDialog
    }
  },
  data: {
    delayRender: !1,
    showPopup: false,
    isCeilingTop: !1,
    headerTop: u
  },
  onLoad: function (e) {
    // this.getToken()
    //  console.log(res)
    var a = this;
    return n(t().mark((function o() {
      var i;
      return t().wrap((function (o) {
        switch (o.prev = o.next) {
          case 0:
            console.log("首页-------", e), e.invite_code && (0, r.dispatch)(r.actions.storageActions.setItem({
              key: "INVITECODE",
              value: e.invite_code
            })), i = setTimeout((function () {
              clearTimeout(i), a.setData({
                delayRender: !0
              })
            }), 1100), (0, s.getLocation)().then(function () {
              var e = n(t().mark((function e(n) {
                var a, o, i, u;
                return t().wrap((function (e) {
                  for (;;) switch (e.prev = e.next) {
                    case 0:
                      if (!n.errMsg) {
                        e.next = 2;
                        break
                      }
                      return e.abrupt("return");
                    case 2:
                      return a = n.adcode, e.next = 5, p.getAreaData();
                    case 5:
                      o = e.sent, i = (0, s.codeSearchCity)(a, o), u = i.city, (0, r.dispatch)(r.actions.storageActions.setItem({
                        key: "userLocationCity",
                        value: u || {}
                      }));
                    case 9:
                    case "end":
                      return e.stop()
                  }
                }), e)
              })));
              return function (t) {
                return e.apply(this, arguments)
              }
            }()).finally((function () {
              a.onRefreshList()
            }));
          case 3:
          case "end":
            return o.stop()
        }
      }), o)
    })))()

  },

  onShow: function () {
    var e = this;
    return n(t().mark((function n() {
      var a, o, i, s, u, p;
      return t().wrap((function (t) {
        for (;;) switch (t.prev = t.next) {
          case 0:
            return i = $.router.getParams(), t.next = 3, l.cityOrClassifyChange(e.oldUserLocationCity, e.oldTypeClassify);
          case 3:
            if (s = t.sent, t.t0 = null != i && i.isMultiRoleSelectUpdate || s, !t.t0) {
              t.next = 8;
              break
            }
            return t.next = 8, e.onRefreshList();
          case 8:
            if (null == i || !i.mode) {
              t.next = 18;
              break
            }
            if (u = c.getTabMode(), (null == i ? void 0 : i.mode) == u) {
              t.next = 16;
              break
            }
            return p = c.getModeTabIndex(null == i ? void 0 : i.mode), t.next = 14, c.setFilterParamsInfo("tabValue", p);
          case 14:
            t.next = 18;
            break;
          case 16:
            return t.next = 18, e.onRefreshList();
          case 18:
            (null === (a = e.data) || void 0 === a || null === (o = a.userInfo) || void 0 === o ? void 0 : o.id) && (0, r.dispatch)(r.actions.userActions.fetchUserInfo());
          case 19:
          case "end":
            return t.stop()
        }
      }), n)
    })))()
  },
  onHide: function () {
    var a = this;
    return n(t().mark((function n() {
      var o, i, s;
      return t().wrap((function (t) {
        for (;;) switch (t.prev = t.next) {
          case 0:
            o = r.store.getState().storage.userLocationCity, a.oldUserLocationCity = e({}, o), i = c.getStorageKey(), s = c.getFilterParamsInfo(i), a.oldTypeClassify = s;
          case 4:
          case "end":
            return t.stop()
        }
      }), n)
    })))()
  },
  onPageScroll: function (e) {
    var r = this;
    return n(t().mark((function o() {
      return t().wrap((function (o) {
        for (;;) switch (o.prev = o.next) {
          case 0:
            r.diamondRegionHeight || a.operateDom.nextTick(n(t().mark((function e() {
              var n;
              return t().wrap((function (e) {
                for (;;) switch (e.prev = e.next) {
                  case 0:
                    return e.next = 2, a.operateDom.getDom("#diamond-region");
                  case 2:
                    n = e.sent, r.diamondRegionHeight = n.height;
                  case 4:
                  case "end":
                    return e.stop()
                }
              }), e)
            })))), r.setData({
              isCeilingTop: !!r.diamondRegionHeight && e.scrollTop >= r.diamondRegionHeight
            });
          case 1:
          case "end":
            return o.stop()
        }
      }), o)
    })))()
  },
  onRefreshList: function () {
    var e = this;
    return n(t().mark((function r() {
      return t().wrap((function (r) {
        for (;;) switch (r.prev = r.next) {
          case 0:
            $.selectComponent.call(e, "#card-list").then(function () {
              var r = n(t().mark((function n(r) {
                return t().wrap((function (t) {
                  for (;;) switch (t.prev = t.next) {
                    case 0:
                      return t.next = 2, r.setRefresh(!0);
                    case 2:
                      return t.next = 4, r.onRefresh();
                    case 4:
                      return t.next = 6, (0, o.moveToTabPlace)(e.data.isCeilingTop, e.diamondRegionHeight);
                    case 6:
                      return t.next = 8, r.setRefresh(!1);
                    case 8:
                    case "end":
                      return t.stop()
                  }
                }), n)
              })));
              return function (e) {
                return r.apply(this, arguments)
              }
            }());
          case 1:
          case "end":
            return r.stop()
        }
      }), r)
    })))()
  },
  onClickInput: function () {
    $.selectComponent.call(this, "#tab-filter").then(function () {
      var e = n(t().mark((function e(n) {
        return t().wrap((function (e) {
          for (;;) switch (e.prev = e.next) {
            case 0:
              return e.next = 2, n.close();
            case 2:
            case "end":
              return e.stop()
          }
        }), e)
      })));
      return function (t) {
        return e.apply(this, arguments)
      }
    }()), $.router.push("/subpackage/search/index")
  },
  onTarBarChange: function (e) {

    var t = e.currentTarget.dataset.item;
    if (t.mode == 99) {
      this.setData({
        showPopup: true
      })
      return false
    }
    if (t.mode && (t.mode !== i.typeMode.recruit ? $.router.push("/subpackage/machine-list-search/index", {
        mode: t.mode
      }) : $.router.push("/pages/recruit/index")), "5" === t.page_value && wx.navigateToMiniProgram({
        appId: i.navigateToMiniProgramAppIdList[0],
        path: "page/index/index",
        envVersion: "release"
      }), "8" === t.page_value && $.router.push("/subpackage/supplier/supplier-list/index"), "6" === t.page_value) {
      if (!this.data.userInfo.id) return void $.router.push("/subpackage/login/auth/index");
      a.helper.subscribe.jumpToSubscribePage(this.data.memberInfo.member_status)
    }
  },

  onCloseInvite: function () {
    (0, r.dispatch)(r.actions.globalActions.setState({
      isShowFreeInviteDialog: !1
    }))
  },
  closePopup: function () {
    this.setData({
      showPopup: !this.data.showPopup
    })
  }
});